#include<stdio.h>
#include<stdlib.h>
#define Max 1024
int main()
{
	char str[Max],filename[Max/2];
	FILE *fp;
	printf("please input string!\n");
	scanf("%s",str);
	printf("please input filename:\n");
	scanf("%s",filename);
	//只写打开文件
	if((fp=fopen(filename,"wb"))==NULL)
	{
		perror("fopen error!");
		exit(0);
	}
	else
	{
		if(fputs(str,fp)==EOF)
		{
			perror("fputs error!");
			exit(-1);
		}
		fclose(fp);
	}
	//只读打开文件
	if((fp=fopen(filename,"rb"))==NULL)
	{
		perror("fopen error!");
		exit(0);
	}
	else
	{
		char s[Max];
		if(fgets(s,Max,fp)==NULL)
		{
			perror("fgets error!");
			exit(0);
		}
		printf("%s",s);
		fclose(fp);
	}
	return 0;
}
